<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" placeholder="请输入1-100的整数">
<input type="button" value="猜一猜" onclick="f1()">
<div>猜一猜</div>
<script>
  let i = document.querySelector("input");
  let d = document.querySelector("div");
  let num = parseInt(Math.random()*100)+1;
  let count = 0;
  console.log(num)
  function f1() {
      count++
      if(i.value>num){
        d.innerText="猜大了"
      }else if(i.value<num){
        d.innerText="猜小了"
      }else if(i.value==num){
        d.innerText="对了,猜了"+count+"次"
        num = parseInt(Math.random()*100)+1;
       count=0
      }
      i.value="";
      console.log(num)



  }
</script>
</body>
</html>